$(function () {
    init_user();
});

function init_user() {

    $.post(ctx+"myCustomer/selectGroupListTree",{},function (r) {
        var array  = r.msg;
        $("#using_json").jstree({
            "core": {
                "multiple": true,//单选
                "data":array
            },
            "checkbox" : {
                "keep_selected_style" : false
            },
            "plugins" : [ "wholerow", "checkbox" ]
        });
        // 获得点击节点的id
        $('#using_json').on("changed.jstree", function (e, data) {
            $("#user-selectfor").empty();
            var inst = data.instance;
            var selectedNode = inst.get_selected() ;
            $.each(selectedNode,function (index,val) {
                if (index >= 31){$JuXue.n_danger("最多只能选择30个");return false;}
                var sel = inst.get_node(val);
                 var nodeid = sel.id;
                 var text =  sel.text;
                 var types = sel.original.types;
                if(nodeid.indexOf("group")  ==  -1 ){ //选择的分组
                    var divapent = " <div class=\"fc-event ui-draggable bg-silver height-25\" types='"+types+"' uuid='"+nodeid+"' text='"+text+"'>\n" +
                        "  <div class=\"fc-event-icon\">" +
                        "   <a href=\"#\" onclick=\"$(this).parent().parent().remove()\"><i class='glyphicon glyphicon-remove text-danger p-t-4 p-l-3'></i></a> &nbsp;&nbsp;"+text+"</div>\n" +
                        " </div>"
                    $("#user-selectfor").append(divapent);
                }
            });
        });
    });
}
/**选择模板上的用户**/
function maksureUser() {
    $("#xialazhanshi").empty();$("#zhanshiButton").empty();

    $("#user-selectfor").children("div").each(function (index) {
        var uuid = $(this).attr("uuid");
        var text = $(this).attr("text");
        var types = $(this).attr("types");
        if (index > 3){
            $("#xialazhanshi").append("<button href=\"#\" onclick='$(this).remove()' uuid='"+uuid+"' types='"+types+"' class=\"btn btn-outline-secondary p-3 m-4 p-l-5 p-r-5 \">"+text+"" +
                "<svg class=\"bi bi-x-circle p-l-5\" width=\"1em\" height=\"1em\" viewBox=\"0 0 16 16\" fill=\"currentColor\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
                "  <path fill-rule=\"evenodd\" d=\"M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z\"/>\n" +
                "  <path fill-rule=\"evenodd\" d=\"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z\"/>\n" +
                "  <path fill-rule=\"evenodd\" d=\"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z\"/>\n" +
                "</svg></button>");
        }else{
            $("#zhanshiButton").append("<button href=\"#\" onclick='$(this).remove()' uuid='"+uuid+"' types='"+types+"' class=\"btn btn-outline-secondary p-3 m-4 p-l-5 p-r-5 \">"+text+"" +
                "<svg class=\"bi bi-x-circle p-l-5\" width=\"1em\" height=\"1em\" viewBox=\"0 0 16 16\" fill=\"currentColor\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
                "  <path fill-rule=\"evenodd\" d=\"M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z\"/>\n" +
                "  <path fill-rule=\"evenodd\" d=\"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z\"/>\n" +
                "  <path fill-rule=\"evenodd\" d=\"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z\"/>\n" +
                "</svg></button>");
        }
    });
    $('#sale_select_user').empty().modal('hide')
}

